package com.dcivision.workflow.applet;

import java.awt.Component;
import java.awt.Insets;

import javax.swing.ImageIcon;
import javax.swing.JToolBar;

public class WorkflowToolBar extends JToolBar {

  public static final String REVISION = "$Revision: 1.5 $";

  private String[] imageFiles =
    { "Left.gif", "Right.gif", "RotCCUp.gif",
      "TrafficRed.gif", "Home.gif", "Print.gif", "Help.gif" };
  private String[] toolbarLabels =
    { "Back", "Forward", "Reload", "Stop", "Home", "Print", "Help" };

  public WorkflowToolBar() {
    super();

    this.setFont(new java.awt.Font("SansSerif", 0, 12));
    this.setDebugGraphicsOptions(0);
    this.setToolTipText("");
    this.setVerifyInputWhenFocusTarget(true);

    Insets margins = new Insets(0, 0, 0, 0);
    for(int i=0; i<toolbarLabels.length; i++) {
      WorkflowToolBarButton button = new WorkflowToolBarButton(createImageIcon(imageFiles[i]));
      button.setToolTipText(toolbarLabels[i]);
      button.setMargin(margins);
      add(button);
    }
  }

  public void setTextLabels(boolean labelsAreEnabled) {
    Component c;
    int i = 0;
    while((c = getComponentAtIndex(i++)) != null) {
      WorkflowToolBarButton button = (WorkflowToolBarButton)c;
      if (labelsAreEnabled) {
        button.setText(button.getToolTipText());
      } else {
        button.setText(null);
      }
    }
  }

  protected ImageIcon createImageIcon(String imgName) {
    String path = imgName;
    java.net.URL imgURL = this.getClass().getResource("/images/" + path);

    if (imgURL != null) {
      return new ImageIcon(imgURL);
    } else { 
      return null;
    }
  }

}